package com.lxk.finance.domain.bo;

import cn.hutool.core.collection.CollUtil;
import com.lxk.finance.domain.AccUserAccount;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.mybatis.core.domain.BaseEntity;

import java.math.BigDecimal;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 用户账户业务对象 acc_user_account
 *
 * @author LXK-RY5
 * @date 2024-07-08
 */
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = AccUserAccount.class, reverseConvertGenerate = false)
public class AccUserAccountBo extends BaseEntity {

    /**
     * ID
     */
    @NotNull(message = "ID不能为空", groups = { EditGroup.class })
    private Long id;

    /**
     * 用户ID
     */
    @NotNull(message = "用户ID不能为空", groups = { AddGroup.class, EditGroup.class })
    private Long userId;

    /**
     * 状态，1开启 0关闭
     */
    @NotNull(message = "状态，1开启 0关闭不能为空", groups = { AddGroup.class, EditGroup.class })
    private Integer status;

    /**
     * 账户类型account_type
     */
    @NotNull(message = "账户类型account_type不能为空", groups = { AddGroup.class, EditGroup.class })
    private Integer accountType;

    /**
     * 余额
     */
    @NotNull(message = "余额不能为空", groups = { AddGroup.class, EditGroup.class })
    private BigDecimal amount;

    /**
     * 用户类型
     */
    @NotBlank(message = "用户类型不能为空", groups = { AddGroup.class, EditGroup.class })
    private String userType;


    @Getter
    @AllArgsConstructor
    public enum AccountType {
        POINT(0, "积分"),
        MONEY(1, "余额"),

        ;
        private final Integer code;

        private final String name;
        private static final Map<Integer, AccountType> map = CollUtil.toList(AccountType.values()).stream().collect(Collectors.toMap(AccountType::getCode, v->v));
        public static Boolean containCode(Integer code ) {
            return map.containsKey(code);
        }
        public static AccountType getByCode(Integer code) {
            return map.get(code);
        }
    }


}
